package com.lune.job.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lune.job.mapper.ArticleMapper;
import com.lune.job.pojo.Article;
import com.lune.job.pojo.ResPageBean;
import com.lune.job.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Caiyilin
 * @since 2022-03-06
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    /**
     * 分页查询文章
     * @param currentPage
     * @param size
     * @param article
     * @return
     */
    @Override
    public ResPageBean queryPage(Integer currentPage, Integer size, Article article) {
        Page<Article> page = new Page<>(currentPage, size);
       IPage<Article> articleIPage = articleMapper.queryPage(page,article);
        ResPageBean resPageBean = new ResPageBean(articleIPage.getTotal(), articleIPage.getPages(), articleIPage.getRecords());
        return resPageBean;
    }

    /**
     * 条件查询文章
     * @param article
     * @return
     */
    @Override
    public List<Article> queryByCon(Article article) {
        return articleMapper.queryByCon(article);
    }
}
